home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / BASIC / 3687.ZIP / PIXDEMO.BAS < prev    next >
BASIC Source File  |  1993-02-15  |  5KB  |  155 lines

  1. 'PIXDEMO.BAS (c) K.Willetts 1992/2
  2. 'Note: Demo Quick Library PIX4? must be loaded.
  3. 'This short program demonstrates just about all you need to know to use
  4. 'Pixshow. Use it to redisplay the 3 included demo .QPX images...
  5. '
  6. '   CGADEMO, EGADEMO, VGADEMO
  7. '
  8. '....by specifying one of the above names as a Command Line argument (via the
  9. 'Run/Modify COMMAND$ QB Editor menu selection above). No need to include the
  10. '.QPX filename extension, that is added in the code below. Ensure the image
  11. 'files are in the same directory as this program. CGADEMO is a 2 color 640 x
  12. '200 image; EGADEMO is a 16 color 640 x 350 image; VGADEMO is a 256 color
  13. '320 x 200 image.
  14.  
  15.  
  16. 'Program Starts...
  17.  
  18.   DEFINT A-Z                                  'Usually useful.
  19.   DECLARE FUNCTION biostobasic (biosmode)     'See below.
  20.   '$INCLUDE: 'PIXSHOW.BI'                     'Get Pixshow declarations.
  21.   CONST FALSE = 0, TRUE = NOT FALSE
  22.   CONST DEFAULTBUFFER = 0                     'See below.
  23.  
  24. 'Because this demo prog can display images in several screen modes we need to
  25. 'query each image file before displaying it to find out which video mode it
  26. 'uses. The qpxheader TYPE is used to get information about an on - disk .QPX
  27. 'image file. qpxheader is declared in PIXSHOW.BI and further described in the
  28. 'on disk manual PIXMAN.COM...
  29.  
  30.   DIM imageinfo AS qpxheader
  31.  
  32. 'Build the image filename string. Image file/pathnames MUST always be
  33. 'explicitly terminated by a zero byte...
  34.  
  35.   image$ = COMMAND$ + ".QPX" + CHR$(0)
  36.   IF LEN(image$) = 5 THEN
  37.     CLS
  38.     PRINT "You must place an image name in COMMAND$. See program comments"
  39.     END
  40.   END IF
  41.  
  42. '...Query the image to get it's screen mode. In .QPX files screen mode
  43. 'numbers follow BIOS numbering. Unfortunately QuickBasic screen mode numbers
  44. 'are different, so the FUNCTION biostobasic(...) has been included in this
  45. 'demo program to handle the conversion...
  46.  
  47.   IF getqpxinfo(imageinfo, image$) THEN
  48.     basicmode = biostobasic(imageinfo.videomode)
  49.   ELSE
  50.     'problem...
  51.     CLS
  52.     PRINT "Error accessing .QPX image file. Program terminated"
  53.     END
  54.   END IF
  55.  
  56. '...Set QB screen mode via SCREEN and matching Pixshow library screen modes
  57. 'via library SUB setqpxmode(...)...
  58.  
  59.   ON ERROR GOTO VideoError
  60.   SCREEN basicmode
  61.   setqpxmode basicmode
  62.   ON ERROR GOTO 0
  63.  
  64. '...Release memory from QB, then call Pixshow lib function setqpxbuffer(...)
  65. 'using the default argument value of zero (DEFAULTBUFFER is declared as 0
  66. 'above). See manual for alternative argument values. The resulting 32k buffer
  67. 'memory is used for decompressing images (In the manual it is called the
  68. 'Parcel Buffer). It is physically located in the FAR HEAP, not in QB's 64k
  69. 'DATA area. SETMEM with a negative argument tells QB to release memory for
  70. 'subsequent use by Pixshow. QB is greedy - it grabs all memory for itself
  71. 'even when running the smallest program...
  72.  
  73.   heap& = SETMEM(-33000)
  74.   IF NOT setqpxbuffer(DEFAULTBUFFER) THEN
  75.     'problem...
  76.     SCREEN 0
  77.     PRINT "Unable to allocate decompression buffer. Program terminated"
  78.     END
  79.   END IF
  80.  
  81. '...OK to load & display image if setqpxbuffer succeeds. The arguments to
  82. 'showqpx(...) are listed at the end of this file...
  83.  
  84.   IF NOT showqpx(650, 0, TRUE, FALSE, image$) THEN
  85.     'problem...
  86.     SCREEN 0
  87.     PRINT "Error occurred loading .QPX image file"
  88.   END IF
  89.   LOCATE 25, 2: PRINT "press any key to end...";
  90.   DO: LOOP WHILE INKEY$ = ""
  91.  
  92. '...Release memory & return it to QB before exiting. A successful call to
  93. 'setqpxbuffer(...) needs a matching call to rlsqpxbuffer. SETMEM with a
  94. 'positive argument returns the memory to QB's pool. Making the argument
  95. 'larger than the original allocation ensures all the memory is released...
  96.  
  97.   rlsqpxbuffer
  98.   heap& = SETMEM(40000)
  99.   SCREEN 0
  100.   END
  101.  
  102. '...END OF PROGRAM
  103.  
  104. 'Errror handlers...
  105.  
  106. VideoError:
  107.   CLS
  108.   PRINT "This machine does not support the videomode needed to redisplay"
  109.   PRINT "the requested image. Program terminated"
  110.   END
  111.  
  112.  
  113. 'Additional Comments...
  114. '======================
  115.  
  116. 'Arguments for showqpx(...), reading left to right...
  117. '
  118. '  horizontal (x) image top left corner position
  119. '  vertical (y) image top left corner position
  120. '  TRUE or FALSE = use/don't use file palette to reset screen colours
  121. '  TRUE or FALSE =  blank/don't blank the screen while loading image
  122. '  zero terminated string containing image path/filename
  123.  
  124. 'Image positioning: to display the image in the same screen location it was
  125. 'at when captured by Pixsnap set x to an impossibly large value (greater than
  126. 'the pixel width of the screen). If showqpx finds a legal x position it will
  127. 'try to reposition the image according to the x & y argument values. For more
  128. 'information see on - disk manual PIXMAN.COM.
  129.  
  130. '*** END OF FILE ***
  131.  
  132. FUNCTION biostobasic (biosmode)
  133.  
  134. 'Convert BIOS screen mode numbers to QB screen mode numbers.
  135.  
  136.   SELECT CASE biosmode
  137.   CASE &H13
  138.     biostobasic = 13     'VGA 320 x 200 x 256
  139.   CASE &H12
  140.     biostobasic = 12     'VGA 640 x 480 x 16
  141.   CASE &H10
  142.     biostobasic = 9      'EGA 640 x 350 x 16
  143.   CASE &HE
  144.     biostobasic = 8      'EGA 640 x 200 x 16
  145.   CASE &HD
  146.     biostobasic = 7      'EGA 320 x 200 x 16
  147.   CASE &H6
  148.     biostobasic = 2      'CGA 640 x 200 x 2
  149.   CASE &H5, &H4
  150.     biostobasic = 1      'CGA 320 x 200 x 4
  151.   END SELECT
  152.  
  153. END FUNCTION
  154.  
  155.